package com.drg.center;


import com.guaike.core.mybatis.generator.EntityGenerator;
import com.guaike.core.mybatis.generator.GeneratorParam;

import java.io.File;
import java.net.URL;

/**
 * 代码自动生成器
 *
 * @Author: zhangxilin
 * @Date: 2021/10/11
 */
public class CodeGenerator {

    /**
     * 作者
     **/
    public static final String AUTHOR = "system";
    /**
     * 数据库配置
     **/
    public static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
    public static final String DB_URL = "jdbc:mysql://112.124.12.20:3306/hospital_drg?useSSL=false&useUnicode=true&characterEncoding=utf8";
    public static final String DB_USER_NAME = "root";
    public static final String DB_PASSWORD = "c15e248579c6bfdf12a8fbaab4964";

    /**
     * 父级包名
     **/
    public static final String PARENT_PACKAGE = "com.drg";
    /**
     * 模块名称
     **/
    public static final String MODULE = "center";
    /**
     * 子路径包（实体类包路径）
     */
    public static final String SUB_PACKAGE = "entity";

    /**
     * 指定生成的表 ， 用 ","分割
     **/
    public static final String TABLES = "sys_depart";

    public static void main(String[] args) throws Exception {
        generator();
    }

    private static void generator() throws Exception {
        ClassLoader classLoader = CodeGenerator.class.getClassLoader();
        String filePath = "bootstrap-dev.yml";
        URL url = classLoader.getResource(filePath);
        File file;
        for (file = new File(url.toURI()); file != null
                && !"target".equalsIgnoreCase(file.getName()); file = file.getParentFile()) {
        }

        if (file != null) {
            final String projectPath = file.getParentFile().getPath();
            System.out.println(projectPath);

            GeneratorParam param = new GeneratorParam();
            param.setProject_dir(projectPath);
            param.setAuthor(AUTHOR);
            param.setDb_driver(DB_DRIVER);
            param.setDb_url(DB_URL);
            param.setDb_user_name(DB_USER_NAME);
            param.setDb_password(DB_PASSWORD);
            param.setTables(TABLES);
            param.setModule(MODULE);
            param.setParent_package(PARENT_PACKAGE);
            param.setSub_package(SUB_PACKAGE);
            EntityGenerator.generator(param);
        }
    }
}
